//
//  ChooseViewControllerTool.m
//  20170207
//
//  Created by xuPeng on 2017/9/27.
//  Copyright © 2017年 一直丶黑曼巴. All rights reserved.
//

#import "ChooseViewControllerTool.h"

@implementation ChooseViewControllerTool

+ (void)chooseRootViewController{
    
    /*
        取出存储的版本号和当前版本号进行比对。
     
     */
    NSString *key = (NSString *)kCFBundleVersionKey;
    NSString *oldVersion = [[NSUserDefaults standardUserDefaults]objectForKey:key];
    
    NSString *version = [NSBundle mainBundle].infoDictionary[key];
    
    if ([oldVersion isEqualToString:version]) {
        // 仅加载广告
        
        

    }else{
        /*
            显示引导页
            首先存储最新版本号
         */
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:version forKey:key];
    }
    
    
}

// 通过分别比对版本号数字大小，来确定是否更新版本
+ (NSInteger)compareVersion:(NSString *)lastVersion oldVersion:(NSString *)oldVersion {
    
    NSArray *last = [lastVersion componentsSeparatedByString:@"."];
    NSArray *now = [oldVersion componentsSeparatedByString:@"."];
    
    for (int i = 0; i < last.count && i < now.count; i++) {
        NSString *leftPartition = [last objectAtIndex:i];
        NSString *rightPartition = [now objectAtIndex:i];
        if (leftPartition.integerValue != rightPartition.integerValue) {
            return leftPartition.integerValue - rightPartition.integerValue;
        }
    }
    return 0;
}
@end
